﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Src="../Shared/Header.ascx" TagName="Header" TagPrefix="uc1" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>包装</title>
    <uc1:Header ID="Header1" runat="server" />
    <script type="text/javascript" language="javascript">
        $(function () {

            $('#grid').datagrid({
                //title: '包装管理',
                iconCls: 'icon-save',
                nowrap: false,                      //数据是否显示在一行里
                striped: true,                      //奇偶行使用不同背景色
                url: '/Package/LoadAllByPage/1',    //从远程站点请求数据的 URL
                fitColumns: true,                   //适应表格的宽度并且防止水平滚动
                fit: true,
                idField: 'Id',                      //标识字段
                remoteSort: true,                   //定义是否从服务器给数据排序
                singleSelect: true,                 //是否允许选中一行
                pagination: true,                   //分页
                rownumbers: true,                   //行号
                animate: true,                      //定义当节点展开或折叠时是否显示动画效果。
                pageSize: 20,                       //每页记录数
                pageList: [10, 20, 30],             //每页记录数列表
                //frozenColumns: [[
	                //{ field: 'Id', checkbox: true}  //和列的特性一样，但是这些列将被冻结在左边
				//]],
                onLoadSuccess: function (data) {
                    var totle = eval(data).total;
                }                
            });

        });


        function submit() {
            $('#form').form('submit', {
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (msg) {
                    var msg1 = eval('(' + msg + ')');
                    if (msg1.IsSuccess) {
                        $.messager.alert('提示', "保存成功", 'info', function () {
                            if ($("#id").val() != "") {
                                $('#win').dialog('close');
                            }
                            $('#grid').datagrid('reload');
                        });
                    }
                    else {
                        $.messager.alert('提示', msg1.Message, "error");
                    }
                },
                error: function () {
                    $.messager.alert('错误', '保存失败！', "error");
                }
            });
        }


        function add() {
            $('#win').dialog({
                title: '新增包',
                iconCls: 'icon-add',
                width: 400,
                height: 186,
                closed: false,
                cache: false,
                href: '/Package/Add/',
                modal: true,
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: submit
                }, {
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        $('#win').dialog('close');
                    }
                }],
                onLoad: function () {
                    $("#TiaoMH").focus();
                    CreateBaoMC("");
                }
            });
        }

        function edit() {
            var row = $('#grid').datagrid('getSelected');
            if (row) {
                $('#win').dialog({
                    title: '修改包',
                    iconCls: 'icon-save',
                    width: 400,
                    height: 186,
                    closed: false,
                    cache: false,
                    href: '/Package/Edit/' + row.Id,
                    modal: true,
                    buttons: [{
                        text: '提交',
                        iconCls: 'icon-ok',
                        handler: submit
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#win').dialog('close');
                        }
                    }],
                    onLoad: function () {
                        $("#TiaoMH").focus();
                        CreateBaoMC(row.BaoBH);                        
                    }
                });
            } else {
                $.messager.alert('提示', '请选择要修改的数据');
                return;
            }
        }

        function del() {
            var rows = $('#grid').datagrid('getSelections');
            if (!rows || rows.length == 0) {
                $.messager.alert('提示', '请选择要删除的数据');
                return;
            }
            var parm;
            $.each(rows, function (i, n) {
                if (i == 0) {
                    parm = "idList=" + n.Id;
                }
                else {
                    parm += "&idList=" + n.Id;
                }
            });
            $.messager.confirm('提示', '是否删除这些数据?', function (r) {
                if (!r) {
                    return;
                }

                $.ajax({
                    type: "POST",
                    url: "/Package/Delete/",
                    data: parm,
                    success: function (msg) {
                        if (msg.IsSuccess != null) {
                            if (msg.IsSuccess) {
                                $.messager.alert('提示', '删除成功！', "info", function () {
                                    $('#grid').datagrid("reload");
                                });
                            }
                            else {
                                $.messager.alert('提示', msg.Message, "error");
                            }
                        } else {
                            eval(msg);
                        }
                    },
                    error: function () {
                        $.messager.alert('错误', '删除失败！', "error");
                    }
                });
            });
        }

        function CreateBaoMC(BaoBH) {
            $("#BaoMC").combogrid({
                panelWidth: 436,
                panelHeight: 308,
                idField: 'Id',
                value:BaoBH,
                textField: 'Name',
                singleSelect: true,                //是否允许选中一行
                pagination: true,                  //分页
                rownumbers: false,                   //行号
                pageSize: 10,                        //每页记录数
                pageList: [10],             //每页记录数列表
                columns: [[
					{ field: 'Name', title: '名称', width: 150 }
                    , { field: 'Description', title: '描述', width: 265 }
				]],
                delay: 500,
                mode: 'remote'
            });
        }
    </script>
</head>
<body class="easyui-layout">
    <div region="center" style="padding: 5px;" border="false">
        <table id="grid" toolbar="#toolbar">
            <thead>
                <tr>
                    <th field="TiaoMH" width="20%">
                        条码号
                    </th>
                    <th field="BaoMC" width="20%">
                        器械包名称
                    </th>
                    <th field="BaoZR" width="20%">
                        包装人
                    </th>
                    <th field="BaoZRQ" width="20%">
                        包装日期
                    </th>
                    <th field="BaoZSJ" width="20%">
                        包装时间
                    </th>
                    <th field="BaoBH" width="20%" hidden=true>
                        包编号
                    </th>
                </tr>
            </thead>
        </table>
        <div id="toolbar" style="padding: 2px; height: auto">
            <a id="btnAdd" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-add" plain="true" onclick="add()">包装</a>
            <a id="btnUpdate" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-edit" plain="true" onclick="edit()">修改</a>
            <a id="btnDelete" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-remove" plain="true" onclick="del()">删除</a>
        </div>
    </div>
    <div id="win" />
</body>
</html>
